<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('今日个股概念整理')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 select-table table-striped">
			<table class="table table-hover no-margins" >
				<thead>
				<tr>
					<th>代码</th>
					<th>名称</th>
					<th>概念</th>
					<th>参考概念</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody id="hot-concept-body">

				</tbody>
			</table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var stocks = [[${stocks}]];

	initTable()


	function initTable(){
		$("#hot-concept-body").empty();
		for(var i in stocks){
			// var concepts = eval ("(" + recentConcept[symbol] + ")") ;
			// stock = JSON.parse(stock)
			appendHotConceptBody(stocks[i])
		}
	}

	function appendHotConceptBody(stock){
		console.log(stock)
		var needAppend = "<tr><td>"+stock['symbol']+"</td><td>"+stock['name']+"</td><td>";
		if(stock['concept']){
			needAppend=needAppend+" <input type=\"text\" id=\""+stock['symbol']+"\" class=\"\" value=\""+stock['concept']+"\"></td>  ";
		}else{
			needAppend=needAppend+" <input type=\"text\" id=\""+stock['symbol']+"\" class=\"\" value=\"\"></td>  ";
		}
		if(stock['conceptThs']){
			needAppend=needAppend+"<td> "+stock['conceptThs']+"</td>  ";
		}else{
			needAppend=needAppend+"<td></td>  ";
		}
		needAppend = needAppend +"<td><a class=\"btn btn-info btn-xs \" href=\"javascript:void(0)\" onclick=\"edit('"+stock['symbol']+"')\">确定</a> <a class=\"btn btn-success btn-xs \" href=\"javascript:void(0)\" onclick=\"hide('"+stock['symbol']+"')\">隐藏</a></td></tr>";
		$("#hot-concept-body").append(needAppend)

	}
	function edit(symbol) {
		console.log(symbol)
		var concepts = $("#"+symbol).val();
		console.log(concepts)
		$.operate.post(ctx + "bk/recentConcept/edit", {"symbol":symbol,"concepts":concepts},function(data){
			for(var i in stocks){
				if(stocks[i]['symbol'] == symbol){
					stocks[i]['concept']=concepts
				}
			}

			initTable();
		});
	// 	$("#recipient-name").val(symbol)
	// 	$("#stock-name-label").text(basicStockName[symbol])
	// 	$("#add-concepts").val(recentConcept[symbol])
	// 	$('#addModal').modal('show');
	}
	function hide(symbol) {
		console.log(symbol)
		for(var i in stocks){
			if(stocks[i]['symbol'] == symbol){
				delete stocks[i];
			}
		}
		initTable();
	}

</script>
</body>
</html>